package com.javaee.ch09.entity;

import com.javaee.ch09.common.base.BaseEntity;
import jakarta.validation.constraints.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.persistence.Entity;
import javax.persistence.Id;

@Entity
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class Reader extends BaseEntity {

    @Id
    @NotNull(message = "Reader ID cannot be null")  // 确保 ReaderId 不为空
    private String readerId;

    @NotNull(message = "Name cannot be null")  // 姓名不能为空
    @Size(min = 1, max = 100, message = "Name must be between 1 and 100 characters")  // 姓名长度限制
    private String name;

    @NotNull(message = "Gender cannot be null")  // 性别不能为空
    @Pattern(regexp = "^(男|女)$", message = "Gender must be either '男' or '女'")  // 只允许 '男' 或 '女'
    private String gender;

    @NotNull(message = "Phone cannot be null")  // 电话不能为空
    @Pattern(regexp = "^[0-9]{10,15}$", message = "Phone must be a valid phone number (10-15 digits)")  // 确保电话格式正确，10-15位数字
    private String phone;

    @NotNull(message = "Email cannot be null")  // 邮箱不能为空
    @Email(message = "Email must be a valid email address")  // 确保邮箱格式合法
    private String email;
}
